
const baseUrl = 'http://localhost:8080/api/v1';

function http(type, url, data, successCallBack) {
    // 如果传入的参数是FormData对象类型，需要设置processData为false，contentType为false
    const isformData = data instanceof FormData;
    let loadingIndex = layer.load({ time: 5000 });
    $.ajax({
        type,
        url: baseUrl + url,
        data,
        processData: isformData ? false : true,
        contentType: isformData ? false : 'application/x-www-form-urlencoded',
        headers: {
            Authorization: localStorage.getItem('bigNews_token')
        },
        success: function (resData) {
            layer.close(loadingIndex);
            // 未登录判断
            if(resData.code && resData.code === 403){
                window.parent.location = './login.html'
                return;
            }
            if (resData.code && resData.code !== 200) {
                layer.msg(resData.msg, {
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
                return;
            }

            // 调用传入的回调函数
            successCallBack(resData);
        }
    })
}